package com.example.mybatisplus.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.mybatisplus.mapper.RecordLogMapper;
import com.example.mybatisplus.model.domain.ConsultMerge;
import com.example.mybatisplus.model.domain.RecordLog;
import com.example.mybatisplus.service.RecordLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lxp
 * @since 2022-05-31
 */
@Service
public class RecordLogServiceImpl extends ServiceImpl<RecordLogMapper, RecordLog> implements RecordLogService {
    @Autowired
    private RecordLogMapper recordLogMapper;
    @Override
    public ConsultMerge queryConsultStuid(Long stu_id) {
        ConsultMerge consultMerge = recordLogMapper.queryConsultStuid(stu_id);
        return consultMerge;
    }

    @Override
    public void add8records(ConsultMerge consultMerge) {
        recordLogMapper.add8records(consultMerge);
    }

    @Override
    public boolean isExist(Long stu_id) {
        List<Long> list = recordLogMapper.isExist(stu_id);
//        System.out.println(!list.isEmpty());
//        System.out.println(list);
//        System.out.println(list.size() != 0);
        return !list.isEmpty() || list.size() != 0;
    }



    @Override
    public void changeRecord(RecordLog recordLog) {
        recordLogMapper.changeRecord(recordLog);
    }

    @Override
    public Integer queryMaxcurrentweek(Long stuId) {
        Integer newweek = recordLogMapper.queryCurrent(stuId);
        newweek++;
        return newweek;
    }

    @Override
    public void updateConsultCount(Long stuId) {
        recordLogMapper.updateConsultCount(stuId);
    }

    @Override
    public List<RecordLog> getall() {

        return recordLogMapper.getall();
//        Integer pageSize=10;
//        Page<RecordLog> page=new Page<>(pageNo,pageSize);
//
//        page=recordLogMapper.getall(page);
//
//        return page.getRecords();
    }

    public void autoend(RecordLog recordLog){
        if (recordLog.getRecordStatus()==11||recordLog.getRecordStatus()==12){
            recordLogMapper.autoend(recordLog.getStuId(),recordLog.getDocId());
        }
    }

    @Override
    public void updateEndDate(Long stuId) {
        ConsultMerge consultMerge = recordLogMapper.queryConsultStuid(stuId);
        Date enddate = consultMerge.getEndDate();
        Calendar endcalender = Calendar.getInstance();
        endcalender.setTime(enddate);
        endcalender.add(Calendar.DATE,7);
        enddate = endcalender.getTime();
        consultMerge.setEndDate(enddate);
        recordLogMapper.updateEndDate(consultMerge);
    }

    @Override
    public String getrecordStatusString(Integer recordStatus) {
        return recordLogMapper.getrecordStatusString(recordStatus);
    }

    @Override
    public void changeRecordxxn(Long id, Long status) {
        recordLogMapper.changeRecordxxn(id, status);
    }


}
